package info.gridworld.actor;


import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.awt.Color;

public class Jumper extends Bug {
	
	
	
	public Jumper() {
		super();
	}

	public Jumper(Color color) {
		super(color);
	}

	private Location getNextTwoLocation() {
		Location next = getLocation().getAdjacentLocation(getDirection());
		Location nextTwo = next.getAdjacentLocation(getDirection());
		return nextTwo;
	}
	
	@Override
	public boolean canMove() {
		
		Grid<Actor> gr = getGrid();
        if (gr == null)
            return false;
		
		Location nextTwo = this.getNextTwoLocation();
		
		if(!gr.isValid(nextTwo)) {
			return false;
		}
		Actor neighbor = gr.get(nextTwo);
		return (neighbor == null) || (neighbor instanceof Flower);
	}


	@Override
	public void move() {
		
        Grid<Actor> gr = getGrid();
        if (gr == null)
            return;
//        Location loc = getLocation();
        Location nextTwo = this.getNextTwoLocation();
        if (gr.isValid(nextTwo))
            moveTo(nextTwo);
        else{
            removeSelfFromGrid();
        	//System.out.println("removeSelfFromGrid");
        }
//        Flower flower = new Flower(getColor());
//        flower.putSelfInGrid(gr, loc);
	}
	
	
	

}
